//
//  AsyncViewController.m
//  Study Swift
//
//  Created by admin on 2019/8/6.
//  Copyright © 2019 猫爷爷的酱醋茶. All rights reserved.
//

#import "AsyncViewController.h"

@interface AsyncViewController ()

@end

@implementation AsyncViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self asyncLoading:^(NSString *html) {
       
            NSLog(@"完成异步回调 %@",html);
    }];
}

-(void)asyncLoading:(void (^)(NSString *html))finished
{
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSLog(@"耗时操作");
        
        //通常加载数据...
        
        //异步完成之后，准备主线程回调
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"准备主线程回调");
            
            finished(@"<html>");
        });
    });
    
    
}

@end
